﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using diidon.util;
using System;
using System.Runtime.InteropServices;
using Beyond;
using MyIdolUIFrameWork;

public class AdsProxy {

    public  delegate void SeeVideoOver();
    public  event SeeVideoOver seeVideoOverEvent;

    public enum VideoType //看视频得奖励的类型
    {
        VideoToGetRuby=0,//减少一次看视频次数
        VideoToResurgence=1,//看视频复活
    }


    public static void init() {
        Ads.initialize(new Ads.CallbackDelegateE(adCallback));
        Ads.showAd(Ads.Type.splash);
    }

    public static VideoType m_videoType;
    public static string m_Key;
    public static int m_T_num;

    public static void PlayVideoByType(VideoType videoType)
    {
        m_videoType = videoType;
        BELog.debug("AdmobController.ShowVideo");
        Ads.showAd(Ads.Type.video);
    }

    public static void PlayVideoByType(VideoType videoType,string key)
    {
        m_videoType = videoType;
        m_Key = key;
        BELog.debug("AdmobController.ShowVideo");
        Ads.showAd(Ads.Type.video);
    }

    public static void PlayVideoByType(VideoType videoType, int t_num)
    {
        m_videoType = videoType;
        m_T_num = t_num;
        BELog.debug("AdmobController.ShowVideo");
        Ads.showAd(Ads.Type.video);
    }
    //-----------------------------------------------------------//

    public static void ShowAdInterstitial()
    {
        
    }
    //-----------------------------------------------------------//
    

    /// <summary>
    /// 广告事件回调
    /// </summary>
    /// <param name="type">广告类型</param>
    /// <param name="eve">事件类型</param>
     static void adCallback(Ads.Type type, Ads.Event eve)
	{
		BELog.debug("AdsProxy.adCallback " + type + ", " + eve);
        GameState.videoReady = false;
		if (eve >= Ads.Event.returned)
		{
            App.resume();
		}

        if (type == Ads.Type.video && eve == Ads.Event.returnedWithViewCompleted)
        {
            if (m_videoType == VideoType.VideoToGetRuby)
            {
                BELog.debug("---此处添加------显示奖励界面+Show AwardDialog+++相应的奖励");
                CurrencyController.CreditBalance(1);
                BELog.debug("---此处添加------刷新显示信息");
                UIManager.Instance.SetVisible(UIName.UIAwardWord, true);
                UIAwardWords.Instance.award_text.text = "恭喜获得一个宝石";
                SelectLevelController.Instance.UpdateInfor();
                BELog.debug(" 添加刷新相关信息*-*-*-*-*");
            }
            else if(m_videoType==VideoType.VideoToResurgence)
            {
                Sound.instance.PlayButton();
                ContinueDialog.Instance.Close();
                MainController.instance.VideoRescurgenceAward();
            }
        }
    }
}

